var __extends = this.__extends || function (d, b) {
    function __() { this.constructor = d; }
    __.prototype = b.prototype;
    d.prototype = new __();
};
var TasksList = (function (_super) {
    __extends(TasksList, _super);
    function TasksList() {
        _super.apply(this, arguments);

    }
    TasksList.prototype.Ready = function () {
        CallService("GET", this.aUrl[5], null, true, function (msg) {
            var fields = new Array("todochk", "progresschk", "donechk", "reopenchk", "unestimatedchk", "taskflt", "bugflt");
            for(var i = 0; i < fields.length; i++) {
                $('#' + fields[i]).attr('checked', msg[i]).click(function () {
                    return Base.Page.Self.FilterView(this.id);
                });
            }
        });
        $("#projectsFilter").multiselect({
            noneSelectedText: 'selection',
            minWidth: 50,
            classes: 'projectFilter',
            close: function () {
                CallService("POST", "FilterByProject", {
                    myprojects: $('select#projectsFilter').val()
                }, true, function () {
                    Base.Page.Self.refreshTaskList();
                });
            }
        }).multiselectfilter();
        this.refreshTaskList();
    };
    TasksList.prototype.refreshTaskList = function () {
        return this.loadTaskList(this.aUrl[1], this.aUrl[0], this.aUrl[2], this.aUrl[3]);
    };
    TasksList.prototype.loadTaskList = function (urlContent, url, urlEdit, urlLoading) {
        CallService('GET', url, {
        }, true, function (data) {
            LoadHtmlAndTemplate(urlContent, 'MainTasksList', data, true, function () {
                $('.setScore').click(function () {
                    var id = $(this).attr('data-id');
                    var score = $(this).attr('data-score');
                    Base.Page.Self.SetScore(id, score);
                });
                $('.taskAction').click(function () {
                    var id = $(this).attr('data-id');
                    var type = $(this).attr('data-type');
                    Base.Page.Self.TaskAction(id, type);
                });
                $('button.buttonClose').button({
                    icons: {
                        primary: "ui-icon-close"
                    },
                    text: false
                });
                $('button.setbutton').button({
                    icons: {
                        primary: "ui-icon-circle-check"
                    },
                    text: false
                });
                $('.edit').editable(urlEdit, {
                    indicator: '<img src="' + urlLoading + '">',
                    tooltip: "Doubleclick to edit...",
                    event: "dblclick",
                    callback: function () {
                    }
                });
                $('.editarea').editable(urlEdit, {
                    type: "autogrow",
                    submit: "Save",
                    indicator: '<img src="' + urlLoading + '">',
                    tooltip: "Doubleclick to edit descriptions...",
                    event: "dblclick",
                    autogrow: {
                        lineHeight: 16,
                        maxHeight: 512
                    },
                    callback: function () {
                    }
                });
            });
        });
    };
    TasksList.prototype.FilterView = function (id) {
        CallService("POST", this.aUrl[4], {
            key: id,
            data: isChecked("#" + id)
        }, true, function () {
            Base.Page.Self.refreshTaskList();
        });
    };
    TasksList.prototype.TaskAction = function (id, typeAction) {
        CallService("POST", this.aUrl[6], {
            id: id,
            typeAction: typeAction
        }, true, function () {
            Base.Page.Self.refreshTaskList();
        });
    };
    TasksList.prototype.SetScore = function (id, score) {
        setScore(id, score, this.aUrl[7]);
    };
    TasksList.prototype.EditDialogComplete = function () {
        this.refreshTaskList();
        $.unblockUI();
        $('#dialog-score').dialog('close');
    };
    TasksList.prototype.showMove = function (id) {
        BlockUi();
        $("#dialog-move").empty();
        return $.ajax({
            url: this.aUrl[8],
            data: {
                id: id
            },
            success: function (htmldata) {
                $('#dialog-move').html(htmldata);
                $.unblockUI();
                $('#dialog-move').dialog({
                    autoOpen: false,
                    width: 500,
                    modal: true,
                    hide: "highlight",
                    buttons: {
                        Cancel: function () {
                            $(this).dialog("close");
                        },
                        "Save": function () {
                            $("#MoveForm").submit();
                        }
                    }
                }).dialog('open');
            }
        });
    };
    TasksList.prototype.initProjectsList = function () {
        CallService("POST", "FilterByProject", {
            myprojects: $('select#projectsFilter').val()
        }, true, function () {
            Base.Page.Self.refreshTaskList();
        });
    };
    return TasksList;
})(Base.Page);
